#!/usr/bin/env bash

# install fpm
#
# On OSX/macOS:
# brew install gnu-tar
#
# On Red Hat systems (Fedora 22 or older, CentOS, etc):
# yum install ruby-devel gcc make rpm-build
#
# On Fedora 23 or newer:
# dnf install ruby-devel gcc make rpm-build
#
# On Debian-derived systems (Debian, Ubuntu, etc):
# apt-get install ruby ruby-dev rubygems gcc make
#
# Installing FPM:
# gem install --no-ri --no-rdoc fpm
#

# check
if [ $# -lt 2 ]; then
    echo "Usage: ./scripts/makepkg [rpm|deb|osxpkg|pacman] [version]"
    exit
fi

# target
target=$1

# version
version=$2

# arch
arch=i386
if [ `getconf LONG_BIT` == "64" ]; then
    arch=x86_64
fi

# platform
plat=linux
if [ `uname` == "Darwin" ]; then
    plat=macosx
fi

# build first
make build

# make xmake wrapper
echo "#/!bin/bash
export XMAKE_PROGRAM_DIR=/usr/local/share/xmake
/usr/local/share/xmake/xmake \"\$@\"
" > /tmp/xmake.sh
chmod 755 /tmp/xmake.sh

# make dep package using fpm
fpm -s dir -t $target -n xmake -v $version -m "<waruqi@gmail.com>" --description "A make-like build utility based on Lua" --url "xmake.io" --license Apache \
        xmake=/usr/local/share/ \
        core/src/demo/demo.b=/usr/local/share/xmake/xmake \
        /tmp/xmake.sh=/usr/local/bin/xmake


